//
//  TransactionCell.swift
//  WalkNovel
//
//  Created by Kevin on 2023/7/10.
//

import UIKit

class TransactionCell: UITableViewCell {
     
    lazy var logoImage: UIImageView = {
        let image = UIImageView(image: UIImage(named: "setting_recharge_gold"))
        return image
    }()
    
    lazy var goldLabel: UILabel = {
        let label = UILabel()
        label.font = .wn_font(name: .bold, size: 14)
        label.textColor = .black
        return label
    }()
    
    lazy var timeLabel: UILabel = {
        let label = UILabel()
        label.font = .wn_font(name: .regular, size: 12)
        label.textColor = .init(named: "gray_999999")
        return label
    }()
    
    lazy var priceLabel: UILabel = {
        let label = UILabel()
        label.textAlignment = .right
        label.font = .wn_font(name: .bold, size: 14)
        label.textColor = .init(named: "red_FE95B4")
        return label
    }()
    
    lazy var lineView: UIView = {
        let view = UIView()
        view.backgroundColor = .init(named: "gray_D0D0D0")
        return view
    }()
    
    var model: RechargeDetailModel? {
        didSet {
            if let m = model {
                goldLabel.attributedText = "+\(m.gold) 金幣".wn_numberChange(.init(named: "red_FE95B4")!, .wn_font(name: .bold, size: 16))
                timeLabel.text = m.time?.wn_toJavaDetailDate()
                priceLabel.text = "USD \(m.price)"
            }
        }
    }
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        selectionStyle = .none
        backgroundColor = .white
        contentView.addSubview(logoImage)
        contentView.addSubview(goldLabel)
        contentView.addSubview(timeLabel)
        contentView.addSubview(priceLabel)
        contentView.addSubview(lineView)
        logoImage.snp.makeConstraints { (make) in
            make.centerY.equalToSuperview()
            make.left.equalTo(12)
            make.width.height.equalTo(36)
        }
        goldLabel.snp.makeConstraints { (make) in
            make.top.equalTo(12)
            make.left.equalTo(logoImage.snp.right).offset(12)
        }
        timeLabel.snp.makeConstraints { (make) in
            make.left.equalTo(goldLabel.snp.left)
            make.bottom.equalTo(-12)
        }
        priceLabel.snp.makeConstraints { (make) in
            make.centerY.equalToSuperview()
            make.right.equalTo(-12)
        }
        lineView.snp.makeConstraints { (make) in
            make.left.equalTo(12)
            make.bottom.right.equalTo(0)
            make.height.equalTo(0.5)
        }
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}
